<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div class="container-fluid">
        <div class="col-sm-12">
            <div class="form-horizontal" role="form">
                <div class="form-group">
                    <label class="col-sm-2 control-label">封面:</label>
                    <div class="col-sm-10">
                        <img src="../images/333.png" height="200" width="200" id="surfaceImg"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="surfaceFile" class="col-sm-2 control-label">封面</label>
                    <div class="col-sm-10">
                        <input type="file" class="form-control files" id="surfaceFile" name="files" multiple=""
                               placeholder="请选择图片">
                    </div>
                </div>
                <div class="form-group">
                    <label for="img1" class="col-sm-2 control-label">其他图片</label>
                    <div class="col-sm-10">
                        <input type="file" class="form-control files" id="img1" multiple="" name="files" placeholder="请选择图片">
                    </div>
                </div>
                <div class="form-group">
                    <label for="img2" class="col-sm-2 control-label"></label>
                    <div class="col-sm-10">
                        <input type="file" class="form-control files" id="img2" multiple="" name="files" placeholder="请选择图片">
                    </div>
                </div>
                <div class="form-group">
                    <label for="info" class="col-sm-2 control-label">描述</label>
                    <div class="col-sm-10">
                        <textarea type="text" class="form-control" id="info" rows="10" cols="50"></textarea>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-default" id="okBtn">确定</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>

        $(document).ready(function () {
            var assets_id;

            $.ajax({
                url: "/fixAssets/getId",
                type: "get",
                dataType: "json",
                success: function (result) {
                    console.log(JSON.stringify(result));
                    assets_id = result.object;
                    console.log("assets_id="+assets_id);
                }
            })



            $("#okBtn").click(function () {
                //    批量上传图片，第一位封面图片
                var formData = new FormData();
                $(".files").each(function () {
                    formData.append('files', this.files[0]);
                })
                console.log(formData);
                formData.append('assets_id',assets_id);
                formData.append('info',$("#info").val());

                $.ajax({
                    url: '/fixAssets/upload',
                    type: 'POST',
                    data: formData,
                    /**
                     *必须false才会自动加上正确的Content-Type
                     */
                    contentType: false,
                    /**
                     * 必须false才会避开jQuery对 formdata 的默认处理
                     * XMLHttpRequest会对 formdata 进行正确的处理
                     */
                    processData: false,
                    success: function (res) {
                        console.log(res);
                        if(res.errorCode==0){
                            alert("上传成功");
                           // $(location).attr("href","bookinfook");
                        }else{
                            alert("更新失败，请检查");
                        }
                    }
                });

            });

        });

    </script>
</body>
</html>